<template>
  <div class="table-container">
    <vab-query-form-left-panel>
      <!-- <el-upload
        class="upload-demo"
        action="http://127.0.0.1:3001/alarm/uploadExcle"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        :multiple="false"
        :limit="1"
        :on-exceed="handleExceed"
        :file-list="fileList"
        :show-file-list="false"
      >
        <el-button size="small" type="primary">导入excle</el-button>
      </el-upload> -->
      <vab-uploadExcle ref="vabUpload" :limit="5" name="file" :size="10" @refreshTable="fetchData" />
      <el-button type="primary" @click="handleShow({ key: 'value' })">数据上传</el-button>
    </vab-query-form-left-panel>
    <!-- <vab-query-form>
      <vab-query-form-right-panel>
        <el-form ref="form" :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input v-model="queryForm.title" placeholder="项目名称/费用号" />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" native-type="submit" type="primary" @click="handleQuery">查询</el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form> -->

    <el-table ref="tableSort" :data="list" :element-loading-text="elementLoadingText" :height="height" @selection-change="setSelectRows">
      <el-table-column label="序号" show-overflow-tooltip width="95">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="费用号" prop="costNumber" show-overflow-tooltip />
      <el-table-column label="设备编码" prop="equipmentCode" show-overflow-tooltip />
      <el-table-column label="治具号" prop="fixtureNumber" show-overflow-tooltip />
      <el-table-column label="报警内容" prop="alarmContent" show-overflow-tooltip />
      <el-table-column label="报警代码" prop="alarmCode" show-overflow-tooltip />
      <el-table-column label="报警等级" prop="alarmLevel" />
      <el-table-column label="发生时间" prop="alarmTime" width="200" />
      <el-table-column label="创建时间" prop="createdTime" width="200" />
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
  import { getAll } from '@/api/alarm'
  import VabUploadExcle from '@/components/VabUploadExcle'

  export default {
    name: 'project',
    filters: {},
    components: {
      VabUploadExcle,
    },
    data() {
      return {
        fileList: [],
        imgShow: true,
        list: [],
        imageList: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        selectRows: '',
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNo: 1,
          pageSize: 20,
          title: '',
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight() + 120
      },
    },
    created() {
      this.fetchData()
    },
    beforeDestroy() {},
    mounted() {},
    methods: {
      handleShow(data) {
        this.$refs['vabUpload'].handleShow(data)
      },
      async fetchData() {
        const { data, total } = await getAll(this.queryForm)
        this.list = data
        this.total = total
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      // handleRemove(file, fileList) {
      //   console.log(file, fileList)
      // },
      // handlePreview(file) {
      //   console.log(file)
      // },
      // handleExceed(files, fileList) {
      //   this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
      // },
      // beforeRemove(file, fileList) {
      //   return this.$confirm(`确定移除 ${file.name}？`)
      // },
    },
  }
</script>
